package org.wisdom.ac.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 请求权限验证过滤器
 * 
 * @author 张智研
 * @date 2022/05/27 12:40
 **/
@SuppressWarnings("NullableProblems")
@Slf4j
public class AcRequestInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
        log.debug("验证请求权限");
        if (handler instanceof HandlerMethod) {
            log.info("用户想执行的操作是:" + request.getRequestURI());
        }
        return HandlerInterceptor.super.preHandle(request, response, handler);
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) {

        log.info("postHandle执行{}", modelAndView);
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) {
        log.info("afterCompletion执行异常", ex);
    }
}
